<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.14.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>DM-CtrlH7-BF-DevProgram: RoboMaster电控组通信协议</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="50x5.png"/></td>
  <td id="projectalign">
   <div id="projectname">DM-CtrlH7-BF-DevProgram<span id="projectnumber">&#160;beta 0.1</span>
   </div>
   <div id="projectbrief">C.ONE Studio Damiao Development Board Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.14.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
$(function() { codefold.init(); });
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search',true);
  $(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(function(){initNavTree('md__c_1_2_users_2_a_s_u_s_2_desktop_2dm-ctrl_h7-balance-9025test_2modules_2master__machine_2_robf3db6ee153d24cdbb8a8c06ea0d4885b.html','',''); });
</script>
<div id="container">
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">RoboMaster电控组通信协议 </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="autotoc_md61"></a></p>
<p>可用于视觉，以及其他自研模块（仅限串口通信）</p>
<blockquote class="doxtable">
<p>TODO:</p>
<ol type="1">
<li>利用F4自带的硬件CRC模块计算校验码，提高速度</li>
<li>增加更多的数据类型支持，使得数据类型也为可配置的 </li>
</ol>
</blockquote>
<h1 class="doxsection"><a class="anchor" id="autotoc_md62"></a>
一、串口配置</h1>
<p>通信方式是串口，配置为波特率 921600，8 位数据位，1 位停止位，无硬件流控，无校验位。</p>
<h1 class="doxsection"><a class="anchor" id="autotoc_md63"></a>
二、数据帧说明</h1>
<p>以下所有低位在前发送，数据长度可变。</p>
<ol type="1">
<li>通信协议格式</li>
</ol>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">帧头  </th><th class="markdownTableHeadNone">数据ID  </th><th class="markdownTableHeadNone">数据  </th><th class="markdownTableHeadLeft">帧尾  </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">protocol_header(4-byte)  </td><td class="markdownTableBodyNone">cmd_id(2-byte)  </td><td class="markdownTableBodyNone">data (n-byte)  </td><td class="markdownTableBodyLeft">frame_tail(2-byte，CRC16，整包校验)  </td></tr>
</table>
<ol type="1">
<li>帧头详细定义</li>
</ol>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">帧头  </th><th class="markdownTableHeadNone">偏移位置  </th><th class="markdownTableHeadNone">字节大小  </th><th class="markdownTableHeadNone">内容  </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">sof(CMD)  </td><td class="markdownTableBodyNone">0  </td><td class="markdownTableBodyNone">1  </td><td class="markdownTableBodyNone">数据帧起始字节，固定值为 0xA5  </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">data_length  </td><td class="markdownTableBodyNone">1  </td><td class="markdownTableBodyNone">2  </td><td class="markdownTableBodyNone">数据帧中 data 的长度  </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">crc_check  </td><td class="markdownTableBodyNone">3  </td><td class="markdownTableBodyNone">1  </td><td class="markdownTableBodyNone">帧头CRC校验  </td></tr>
</table>
<ol type="1">
<li>cmd_id 命令码 ID 说明 <b>(字节偏移 4，字节大小 2)</b></li>
</ol>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">命令码  </th><th class="markdownTableHeadNone">数据段长度  </th><th class="markdownTableHeadNone">功能说明  </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">0x0001(可修改)  </td><td class="markdownTableBodyNone">2 byte (16-bit)  </td><td class="markdownTableBodyNone">视觉数据  </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">.......  </td><td class="markdownTableBodyNone"></td><td class="markdownTableBodyNone"></td></tr>
</table>
<ol type="1">
<li>数据段data (n-byte)</li>
</ol>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">数据  </th><th class="markdownTableHeadNone">偏移位置  </th><th class="markdownTableHeadNone">字节大小  </th><th class="markdownTableHeadNone">内容  </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">flags_register  </td><td class="markdownTableBodyNone">6  </td><td class="markdownTableBodyNone">2  </td><td class="markdownTableBodyNone">16位标志置位寄存器  </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">float_data  </td><td class="markdownTableBodyNone">8  </td><td class="markdownTableBodyNone">4 * data_length  </td><td class="markdownTableBodyNone">float数据内容（4 * data_length-byte）  </td></tr>
</table>
<ol type="1">
<li>frame_tail(CRC16，整包校验)</li>
</ol>
<h1 class="doxsection"><a class="anchor" id="autotoc_md64"></a>
三、协议接口说明</h1>
<div class="fragment"><div class="line"><span class="comment">/*更新发送数据帧，并计算发送数据帧长度*/</span></div>
<div class="line"><span class="keywordtype">void</span> get_protocol_send_data(uint16_t send_id,        <span class="comment">//信号id</span></div>
<div class="line">                            uint16_t flags_register, <span class="comment">// 16位寄存器</span></div>
<div class="line">                            <span class="keywordtype">float</span> *tx_data,          <span class="comment">//待发送的float数据</span></div>
<div class="line">                            uint8_t float_length,    <span class="comment">// float的数据长度</span></div>
<div class="line">                            uint8_t *tx_buf,         <span class="comment">//待发送的数据帧</span></div>
<div class="line">                            uint16_t *tx_buf_len);   <span class="comment">//待发送的数据帧长度</span></div>
</div><!-- fragment --><p>将float_data字段准备好放入<span class="tt">tx_data[]</span>并设置好标志位<span class="tt">flags_register</span>之后，调用此函数。它将计算循环冗余校验码，并把数据转换成串口发送的格式，放在<span class="tt">tx_buf[]</span>中。</p>
<div class="fragment"><div class="line"><span class="comment">/*接收数据处理*/</span></div>
<div class="line">uint16_t get_protocol_info(uint8_t *rx_buf,          <span class="comment">//接收到的原始数据</span></div>
<div class="line">                           uint16_t *flags_register, <span class="comment">//接收数据的16位寄存器地址</span></div>
<div class="line">                           <span class="keywordtype">float</span> *rx_data);          <span class="comment">//接收的float数据存储地址</span></div>
</div><!-- fragment --><p>将收到的一包原始数据buff地址传入，若校验通过，会把收到的标志位和float数据解析出来，保存在<span class="tt">flags_register*</span>和 <span class="tt">rx_data[]</span>中。 </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<div id="page-nav" class="page-nav-panel">
<div id="page-nav-resize-handle"></div>
<div id="page-nav-tree">
<div id="page-nav-contents">
</div><!-- page-nav-contents -->
</div><!-- page-nav-tree -->
</div><!-- page-nav -->
</div><!-- container -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.14.0 </li>
  </ul>
</div>
</body>
</html>
